<template>
  <div class="dialog-container">
    <div class="dialog-content">
      <!--搜索-->
      <div class="panel-container">
        <SearchUiNew ref="SearchUiNew" :searchFormArr="searchFormArr" @searchParma="searchParma"></SearchUiNew>
      </div>
      <!--数据信息-->
      <div class="panel-container no-margin">
        <el-radio-group v-model="tabActive" style="margin-top: -10px; margin-bottom: 10px" size="mini" @change="handelTabChange">
          <el-radio-button v-for="item in tabList" :key="item.id" :label="item.id">{{ item.label }}</el-radio-button>
        </el-radio-group>
        <el-table stripe :data="dataList" size="mini" :header-cell-style="{ background: '#F5F5F5', color: '#000000' }" ref="table" style="width: 100%" v-loading="dataListLoading">
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="日期" width="200">
            <template slot-scope="scope">
              <template v-if="tabActive === 1">{{ scope.row.work_date }}</template>
              <template v-if="tabActive === 2">{{ scope.row.week }}</template>
              <template v-if="tabActive === 3">{{ scope.row.month }}</template>
            </template>
          </af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="员工姓名" prop="user_name"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="采集申领量" prop="1"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="采集发布量" prop="2"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="采集删除量" prop="3"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="用户发布申领量" prop="5"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="员工发布" prop="4"></af-table-column>
        </el-table>
        <el-pagination
          small
          background
          :current-page="pageNumber"
          :page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="pageTotal"
          @current-change="currentChangeHandle"
          @size-change="sizeChangeHandle"
          layout="total, sizes, prev, pager, next, jumper"
          style="margin-top: 20px; text-align: right"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { apiWokerCountList } from '@/api/assetsPublic'

export default {
  name: 'DialogJobLog',
  props: {
    time: Object,
  },
  components: {},
  data() {
    return {
      tabActive: 1,
      tabList: [
        { id: 1, label: '按日' },
        { id: 2, label: '按周' },
        { id: 3, label: '按月' },
      ],
      searchFormArr: [
        {
          fieldName: '员工:',
          type: 'select',
          field: 'user_id',
          option: [],
          placeholder: '请选择',
        },
        {
          fieldName: '时间',
          type: 'timePicker',
          field: 'time',
          placeholder: '请选择时间',
          timeType: 'daterange',
          format: 'yyyy-MM-dd',
        },
      ],

      searchParams: {
        user_id: '',
        start_time: '',
        end_time: '',
      },
      dataList: [],
      pageNumber: 1,
      pageSize: 10,
      pageTotal: 0,
      dataListLoading: false,
      editMode: 'add',
      currentId: '',
      showOfflineSign: false,
      showOfflineSignView: false,
      url: '', // 合同地址
    }
  },
  activated() {
    this.$refs.table.doLayout()
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.$store.dispatch('select/getUserList').then((res) => {
        this.searchFormArr.find((item) => item.field === 'user_id').option = res
      })
      if (this.time) {
        const { start_time, end_time } = this.time
        this.searchParams.start_time = start_time
        this.searchParams.end_time = end_time
        this.$nextTick(() => {
          this.$refs.SearchUiNew.setItemValue([{ key: 'time', value: [start_time, end_time] }])
        })
      } else {
        this.getDataList()
      }
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      const info = Object.assign({ pageNumber: this.pageNumber, pageSize: this.pageSize, method: this.tabActive }, this.searchParams)
      apiWokerCountList(info)
        .then((res) => {
          const { data, total } = res
          this.dataList = data
          this.pageTotal = total
          this.dataListLoading = false
          this.$refs.table.doLayout()
        })
        .catch((e) => {
          this.dataList = []
          this.pageTotal = 0
          this.dataListLoading = false
        })
    },
    // 列表查询
    searchParma(e) {
      this.searchFormArr.forEach((item) => {
        if (item.field === 'time') return
        if (e[item.field]) {
          this.searchParams[item.field] = e[item.field]
        } else {
          this.searchParams[item.field] = ''
        }
      })
      if (e.time) {
        this.searchParams.start_time = e.time[0]
        this.searchParams.end_time = e.time[1]
      } else {
        this.searchParams.start_time = this.searchParams.end_time = ''
      }
      this.pageNumber = 1
      this.getDataList()
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageNumber = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageNumber = val
      this.getDataList()
    },
    // 切换tab
    handelTabChange() {
      this.pageNumber = 1
      this.getDataList()
    },
  },
}
</script>

<style scoped lang="scss">
.panel-line {
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
